/*
 * Copyright (C) 2009, 2010, B3log Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Description: New file.
 * Version: 1.0.0.0, Jun 10, 2010
 * Author: Liyuan Li
 */
var step = {
    datas: {
        'stepNum': 0,
        'type': '',
        'steps': []
    },

    init: function(stepsDatas){
        this.datas.type = stepsDatas.type;
        this.datas.steps = stepsDatas.steps;
        this.initState();
    },

    cancel: function(){
        $('#' + this.datas.type).hide();
        this.datas = {
            'stepNum': 0,
            'type': '',
            'steps': []
        };
    },

    initState: function(){
        $('#' + this.datas.type).show();
        //this.bgDisabled();
        for(var i = 0; i < this.datas.steps.length; i++){
            if (i == 0){
                $('#' + this.datas.steps[i] + 'Main').show();
                $('#' + this.datas.steps[i] + 'Step').show();
            }else{
                $('#' + this.datas.steps[i] + 'Main').hide();
                $('#' + this.datas.steps[i] + 'Step').hide();
            }
        }
        $('#' + this.datas.type + 'Next').removeAttr('disabled');
        $('#' + this.datas.type + 'Back').attr('disabled', 'disabled');
    },

    bgDisabled: function(){
        $('#' + this.datas.type).click(function(arg1, arg2, agr3){
            alert(1);
        }).css('cursor', 'wait');
    },

    backAndNext: function(mark) {
        if(mark == 'back') {
            this.datas.stepNum--;
        }else{
            this.datas.stepNum++;
        }
        var stepsLength = this.datas.steps.length;
        for(var i = 0; i < stepsLength; i++){
            if(this.datas.stepNum == i){
                $('#' + this.datas.steps[i] + 'Main').show();
                $('#' + this.datas.steps[i] + 'Step').show();
            }else{
                $('#' + this.datas.steps[i] + 'Main').hide();
                $('#' + this.datas.steps[i] + 'Step').hide();
            }
            if(this.datas.stepNum == 0){
                $('#' + this.datas.type + 'Next').removeAttr('disabled');
                $('#' + this.datas.type + 'Back').attr('disabled', 'disabled');
            }else if(this.datas.stepNum == stepsLength - 1){
                $('#' + this.datas.type + 'Back').removeAttr('disabled');
                $('#' + this.datas.type + 'Next').attr('disabled', 'disabled');
            }else{
                $('#' + this.datas.type + 'Next').removeAttr('disabled');
                $('#' + this.datas.type + 'Back').removeAttr('disabled');
            }
        }
    }
};
var finished = {
    newFile: function(){
        $("#newFile").hide();
        var requestJSONObject = {
            "projectGroupId": this.data.projectGroupId.val(),
            "projectArtifactId": this.data.projectArtifactId.val(),
            "projectVersion": this.data.projectVersion.val()
        };
        output.clear();
        jsonRpc.mavenService.genSampleFile(function(result, error) {
            // TODO: output.setText(result.msgs);
            projectSpaceTree.refresh();
        }, requestJSONObject);
    },

    newProject:  function(){
        $("#newProject").hide();
        var requestJSONObject = {
            "projectGroupId": $('#projectGroupId').val(),
            "projectArtifactId": $('#projectArtifactId').val(),
            "projectVersion": $('#projectVersion').val()
        };
        alert(JSON.stringify(requestJSONObject));
        output.clear();
        jsonRpc.mavenService.genSampleProject(function(result, error) {
            // TODO: output.setText(result.msgs);
            projectSpaceTree.refresh();
        }, requestJSONObject);
    }
};